The present disclosure relates to performance optimizations of computer programs in general, and to field affinity estimation based on an execution by a computer having a plurality of processing entities in particular.
Performance of a computer program may be improved based on performance optimizations methods. Such methods include modifying the computer program, also referred to as a target program, to perform in a more efficient manner such as for example to be executed more rapidly, to require less resources such as memory space or draw less power. Although referred to as optimizing performance of the target program, such methods do not necessarily provide the best possible performance. In some cases, performing an optimization may unfortunately lead to a reduction in efficiency of the target program in some executions or even unexpectedly in all executions.
Data layout optimizations are utilized to change an individual record layout used in the target program so as to better correspond to data access patterns exercised by the target program. Some optimizations utilize affinity between fields of the record to determine the record layout in the optimized target program. For example, a record, such as for example a c-like structure, having four fields: f1,f2,f3,f4 may be frequently utilized by the target program by accessing field f2 before accessing field f4 and by accessing field f1 after accessing field f3. The affinity between fields f1 and f3 and between fields f2 and f4 may be utilized. The optimized target program may define a record with the fields arranged in a different manner, such as for example, f3,f1,f2,f4. The different data layout may take into account the order of accesses (e.g., field f3 is often accessed before field f1) and the group of fields accessed in proximate instructions (e.g., fields f3 and f1 are usually accessed together or in relatively close instructions) or the like.
Data layout optimizations may be utilized in a compiler, as is known in the art, to optimize the compiled target program. At compile time, the compiler may utilize the affinity between fields to determine a data layout associated with a record. The data layout may be different than that defined by the target program (e.g., by the code defining the record). The compiler may modify the target program so that the compiled target program may have the substantially same effect as though the data layout was as defined, except for improved performance. The improved performance may be achieved due to spatial locality improvement, as is known in the art.